from right_img import right_img
from PyQt5 import QtCore, QtGui, QtWidgets
import sys, base64, sip
import qtawesome, requests, re
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QCursor, QImage, QPixmap
from io import BytesIO

class Right_UI(right_img):
    def right_post_get_imag(self,book_num_input):
        self.iico

    def right_ui(self):
        self.right_recommend_label = QtWidgets.QLabel("今日推荐")
        self.right_recommend_label.setObjectName('right_lable')

        self.right_refresh_button_1 = QtWidgets.QPushButton(qtawesome.icon('fa.refresh', color='gray'), "")
        self.right_refresh_button_1.setObjectName('right_refresh')
        self.right_recommend_widget = QtWidgets.QWidget()  # 推荐封面部件
        self.right_recommend_layout = QtWidgets.QGridLayout()  # 推荐封面网格布局
        self.right_recommend_widget.setLayout(self.right_recommend_layout)

        self.recommend_button_1 = QtWidgets.QToolButton()
        self.recommend_button_1.setText(self.items[0][2])  # 设置按钮文本
        self.recommend_button_1.setIcon(self.ico(self.iico[0]))  # 设置按钮图标
        self.recommend_button_1.setIconSize(QtCore.QSize(100, 100))  # 设置图标大小
        self.recommend_button_1.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)  # 设置按钮形式为上图下文
        self.recommend_button_1.setFont(QtGui.QFont('SansSerif', 10))
        self.recommend_button_1.setToolTip(self.items[0][2])
        self.book_num_1=int(self.items[0][0])-1
        self.recommend_button_1.clicked.connect(lambda:self.right_book_ui(book_num=self.book_num_1))

        self.recommend_button_2 = QtWidgets.QToolButton()
        self.recommend_button_2.setText(self.items[1][2])
        self.recommend_button_2.setIcon(self.ico(self.iico[1]))
        self.recommend_button_2.setIconSize(QtCore.QSize(100, 100))
        self.recommend_button_2.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.recommend_button_2.setFont(QtGui.QFont('SansSerif', 10))
        self.recommend_button_2.setToolTip(self.items[0][2])
        self.book_num_2 = int(self.items[1][0]) - 1
        self.recommend_button_2.clicked.connect(lambda: self.right_book_ui(book_num=self.book_num_2))

        self.recommend_button_3 = QtWidgets.QToolButton()
        self.recommend_button_3.setText(self.items[2][2])
        self.recommend_button_3.setIcon(self.ico(self.iico[2]))
        self.recommend_button_3.setIconSize(QtCore.QSize(100, 100))
        self.recommend_button_3.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.recommend_button_3.setFont(QtGui.QFont('SansSerif', 10))
        self.recommend_button_3.setToolTip(self.items[0][2])
        self.book_num_3 = int(self.items[2][0]) - 1
        self.recommend_button_3.clicked.connect(lambda: self.right_book_ui(book_num=self.book_num_3))

        self.recommend_button_4 = QtWidgets.QToolButton()
        self.recommend_button_4.setText(self.items[3][2])
        self.recommend_button_4.setIcon(self.ico(self.iico[3]))
        self.recommend_button_4.setIconSize(QtCore.QSize(100, 100))
        self.recommend_button_4.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.recommend_button_4.setFont(QtGui.QFont('SansSerif', 10))
        self.recommend_button_4.setToolTip(self.items[0][2])
        self.book_num_4 = int(self.items[3][0]) - 1
        self.recommend_button_4.clicked.connect(lambda: self.right_book_ui(book_num=self.book_num_4))

        self.recommend_button_5 = QtWidgets.QToolButton()
        self.recommend_button_5.setText(self.items[4][2])
        self.recommend_button_5.setIcon(self.ico(self.iico[4]))
        self.recommend_button_5.setIconSize(QtCore.QSize(100, 100))
        self.recommend_button_5.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.recommend_button_5.setFont(QtGui.QFont('SansSerif', 10))
        self.recommend_button_5.setToolTip(self.items[0][2])
        self.book_num_5 = int(self.items[4][0]) - 1
        self.recommend_button_5.clicked.connect(lambda: self.right_book_ui(book_num=self.book_num_5))

        self.recommend_button_6 = QtWidgets.QToolButton()
        self.recommend_button_6.setText(self.items[5][2])
        self.recommend_button_6.setIcon(self.ico(self.iico[5]))
        self.recommend_button_6.setIconSize(QtCore.QSize(100, 100))
        self.recommend_button_6.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        self.recommend_button_6.setFont(QtGui.QFont('SansSerif', 10))
        self.recommend_button_6.setToolTip(self.items[0][2])
        self.book_num_6 = int(self.items[5][0]) - 1
        self.recommend_button_6.clicked.connect(lambda: self.right_book_ui(book_num=self.book_num_6))

        self.right_recommend_layout.addWidget(self.recommend_button_1, 0, 0)
        self.right_recommend_layout.addWidget(self.recommend_button_2, 0, 1)
        self.right_recommend_layout.addWidget(self.recommend_button_3, 0, 2)
        self.right_recommend_layout.addWidget(self.recommend_button_4, 0, 3)
        self.right_recommend_layout.addWidget(self.recommend_button_5, 0, 4)
        self.right_recommend_layout.addWidget(self.recommend_button_6, 0, 5)

        self.right_layout.addWidget(self.right_recommend_label, 1, 0, 1, 9)
        self.right_layout.addWidget(self.right_refresh_button_1, 1, 1, 1, 1)
        self.right_refresh_button_1.setFixedSize(20, 20)
        self.right_layout.addWidget(self.right_recommend_widget, 2, 0, 2, 9)
        self.right_newsong_lable = QtWidgets.QLabel("最新榜单")
        self.right_newsong_lable.setObjectName('right_lable')
        self.right_playlist_lable = QtWidgets.QLabel("热门书籍")
        self.right_playlist_lable.setObjectName('right_lable')
        self.right_newsong_widget = QtWidgets.QWidget()  # 最新榜单部件
        self.right_newsong_layout = QtWidgets.QGridLayout()  # 最新榜单部件网格布局
        self.right_newsong_widget.setLayout(self.right_newsong_layout)

        self.newsong_button_1 = QtWidgets.QPushButton("大奉打更人 第一章")
        self.newsong_button_2 = QtWidgets.QPushButton("稳住别浪 第一章")
        self.newsong_button_3 = QtWidgets.QPushButton("我真的是正派 第一章")
        self.newsong_button_4 = QtWidgets.QPushButton("万族之劫 第一章")
        self.newsong_button_5 = QtWidgets.QPushButton("建造狂魔 第一章")
        self.newsong_button_6 = QtWidgets.QPushButton("东晋北府一丘八 第一章")
        self.newsong_button_7 = QtWidgets.QPushButton("长夜余火 第一章")
        self.newsong_button_8 = QtWidgets.QPushButton("掌门低调点 第一章")
        self.newsong_button_9 = QtWidgets.QPushButton("全职艺术家 第一章")
        self.newsong_button_10 = QtWidgets.QPushButton("从红月开始 第一章")
        self.newsong_button_11 = QtWidgets.QPushButton("轮回乐园 第一章")
        self.newsong_button_12 = QtWidgets.QPushButton("大梦主 第一章")

        self.right_newsong_layout.addWidget(self.newsong_button_1, 0, 1, )
        self.right_newsong_layout.addWidget(self.newsong_button_2, 1, 1, )
        self.right_newsong_layout.addWidget(self.newsong_button_3, 2, 1, )
        self.right_newsong_layout.addWidget(self.newsong_button_4, 3, 1, )
        self.right_newsong_layout.addWidget(self.newsong_button_5, 4, 1, )
        self.right_newsong_layout.addWidget(self.newsong_button_6, 5, 1, )
        self.right_newsong_layout.addWidget(self.newsong_button_7, 0, 2, )
        self.right_newsong_layout.addWidget(self.newsong_button_8, 1, 2, )
        self.right_newsong_layout.addWidget(self.newsong_button_9, 2, 2, )
        self.right_newsong_layout.addWidget(self.newsong_button_10, 3, 2, )
        self.right_newsong_layout.addWidget(self.newsong_button_11, 4, 2, )
        self.right_newsong_layout.addWidget(self.newsong_button_12, 5, 2, )

        self.right_playlist_widget = QtWidgets.QWidget()  # 播放歌单部件
        self.right_playlist_layout = QtWidgets.QGridLayout()  # 播放歌单网格布局
        self.right_playlist_widget.setLayout(self.right_playlist_layout)
        self.playlist_button_1 = QtWidgets.QToolButton()
        self.playlist_button_1.setText(self.items[0][2])
        self.playlist_button_1.setIcon(self.ico(self.iico[0]))
        self.playlist_button_1.setIconSize(QtCore.QSize(100, 100))
        self.playlist_button_1.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.playlist_button_2 = QtWidgets.QToolButton()
        self.playlist_button_2.setText(self.items[1][2])
        self.playlist_button_2.setIcon(self.ico(self.iico[1]))
        self.playlist_button_2.setIconSize(QtCore.QSize(100, 100))
        self.playlist_button_2.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.playlist_button_3 = QtWidgets.QToolButton()
        self.playlist_button_3.setText(self.items[2][2])
        self.playlist_button_3.setIcon(self.ico(self.iico[2]))
        self.playlist_button_3.setIconSize(QtCore.QSize(100, 100))
        self.playlist_button_3.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.playlist_button_4 = QtWidgets.QToolButton()
        self.playlist_button_4.setText(self.items[3][2])
        self.playlist_button_4.setIcon(self.ico(self.iico[3]))
        self.playlist_button_4.setIconSize(QtCore.QSize(100, 100))
        self.playlist_button_4.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.playlist_button_5 = QtWidgets.QToolButton()
        self.playlist_button_5.setText(self.items[4][2])
        self.playlist_button_5.setIcon(self.ico(self.iico[4]))
        self.playlist_button_5.setIconSize(QtCore.QSize(100, 100))
        self.playlist_button_5.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.playlist_button_6 = QtWidgets.QToolButton()
        self.playlist_button_6.setText(self.items[5][2])
        self.playlist_button_6.setIcon(self.ico(self.iico[5]))
        self.playlist_button_6.setIconSize(QtCore.QSize(100, 100))
        self.playlist_button_6.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.right_playlist_layout.addWidget(self.playlist_button_1, 0, 0)
        self.right_playlist_layout.addWidget(self.playlist_button_2, 0, 1)
        self.right_playlist_layout.addWidget(self.playlist_button_3, 0, 2)
        self.right_playlist_layout.addWidget(self.playlist_button_4, 1, 0)
        self.right_playlist_layout.addWidget(self.playlist_button_5, 1, 1)
        self.right_playlist_layout.addWidget(self.playlist_button_6, 1, 2)

        self.right_layout.addWidget(self.right_newsong_lable, 4, 0, 1, 5)
        self.right_layout.addWidget(self.right_playlist_lable, 4, 5, 1, 4)
        self.right_layout.addWidget(self.right_newsong_widget, 5, 0, 1, 5)
        self.right_layout.addWidget(self.right_playlist_widget, 5, 5, 1, 4)
        self.console_button_1 = QtWidgets.QPushButton(qtawesome.icon('fa.backward', color='#F76677'), "")
        self.console_button_2 = QtWidgets.QPushButton(qtawesome.icon('fa.forward', color='#F76677'), "")
        self.console_button_3 = QtWidgets.QPushButton(qtawesome.icon('fa.pause', color='#F76677', font=18), "")
        self.console_button_3.setIconSize(QtCore.QSize(30, 30))
        # self.right_playconsole_layout.addWidget(self.console_button_1, 0, 0)
        # self.right_playconsole_layout.addWidget(self.console_button_2, 0, 2)
        # self.right_playconsole_layout.addWidget(self.console_button_3, 0, 1)
        # self.right_playconsole_layout.setAlignment(QtCore.Qt.AlignCenter) # 设置布局内部件居中显示
        # self.right_layout.addWidget(self.right_process_bar, 9, 0, 1, 9)
        # self.right_layout.addWidget(self.right_playconsole_widget, 10, 0, 1, 9)

        self.right_recommend_widget.setStyleSheet(
            '''
            QToolButton{border:none;}
            QToolButton:hover{border-bottom:2px solid #F76677;}
            ''')
        self.right_playlist_widget.setStyleSheet(
            '''
            QToolButton{border:none;}
            QToolButton:hover{border-bottom:2px solid #F76677;}
            ''')
        self.right_newsong_widget.setStyleSheet('''
                   QPushButton{
                   border:none;
                   color:gray;
                   font-size:12px;
                   height:40px;
                   padding-left:5px;
                   padding-right:10px;
                   text-align:left;
                   }
                   QPushButton:hover{
                   color:black;
                   border:1px solid #F3F3F5;
                   border-radius:10px;
                   background:LightGray;
                   }
                   ''')